package com.lll.simple.rpc.protocol.serialization;

/**
 * @Author: liull
 * @Description: 获取序列化实现的工厂类
 * @Date: Created in 14:19 2021/2/4
 * @Modified By:
 */
public class SerializationFactory {

    private volatile static RpcSerialization serialization;

    public static RpcSerialization getSerializationByType(byte type) {
        SerializationTypeEnum typeEnum = SerializationTypeEnum.findByType(type);
        if (null == serialization) {
            synchronized (SerializationFactory.class) {
                if (null == serialization) {
                    switch (typeEnum) {
                        case JSON:
                            serialization = new JsonSerialization();
                            break;
                        case KRYO:
                            serialization = new KryoSerialization();
                            break;
                        default:
                            serialization = new HessianSerialization();
                    }
                }
            }
        }
        return serialization;
    }
}
